package com.idea.common.result;

import java.io.Serializable;
import java.util.List;

import com.idea.common.utils.ThreadLocalGson;

public class ResultList<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Integer totalItem = 0;

	private List<T> itemList;

	private boolean success = true;

	private String message = "";

	public final String resultType = "ResultList";

	public static <T> ResultList<T> buildSuccessResult(List<T> list, int totalItem) {
		ResultList<T> result = new ResultList<T>();
		result.setItemList(list);
		result.setTotalItem(totalItem);
		return result;
	}

	public static <T> ResultList<T> buildFailedResult(String message) {
		ResultList<T> result = new ResultList<T>();
		result.setSuccess(false);
		result.setMessage(message);
		return result;
	}

	public Integer getTotalItem() {
		return totalItem;
	}

	public ResultList<T> setTotalItem(Integer totalItem) {
		this.totalItem = totalItem;
		return this;
	}

	public List<T> getItemList() {
		return itemList;
	}

	public ResultList<T> setItemList(List<T> itemList) {
		this.itemList = itemList;
		return this;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getMessage() {
		return message;
	}

	public ResultList<T> setMessage(String message) {
		this.message = message;
		return this;
	}

	public String toJson() {
		return ThreadLocalGson.getGson().toJson(this);
	}

	public String getResultType() {
		return resultType;
	}

	@Override
	public String toString() {
		return toJson();
	}

}
